package com.example.demo.task;

import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;

import java.util.HashMap;
import java.util.Map;

/**
 * 根据发起人，选择直接领导
 *
 * @Author hweiyu
 * @Description
 * @Date 2022/7/11 10:27
 */
public class ChooseLeaderTaskListener implements TaskListener {

    @Override
    public void notify(DelegateTask delegateTask) {
        String starter = (String) delegateTask.getVariable("starter");
        String leader = getLeader(starter);
        delegateTask.setAssignee(leader);
    }

    private String getLeader(String starter) {
        Map<String, String> directLeaderMap = new HashMap<>();
        directLeaderMap.put("张三", "赵领导");
        directLeaderMap.put("李四", "黄领导");
        directLeaderMap.put("王五", "周领导");
        return directLeaderMap.getOrDefault(starter, "大领导");
    }
}
